package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args){
        try(Connection connection = DBUtil.getConnection();) {
            Statement statement = connection.createStatement();
            String sql = "SELECT s.id,s.name,s.job,c.name,c.floor FROM student s JOIN class c ON s.class_id= c.id WHERE c.name='1年级1班'";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                int id = rs.getInt("s.id");
                String name = rs.getString("s.name");
                String job = rs.getString("s.job");
                String className = rs.getString("c.name");
                int floor = rs.getInt("c.floor");
                System.out.println(id+"--"+name+"--"+job+"--"+className+"--"+floor);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
